package org.ceteca.explica.core.common;


/**
 * Store class to hold the data of a price list line.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of flag data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Juan Díaz <juancarlosdiaz@ceteca.es>
 * Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


import java.io.Serializable;
import java.math.BigDecimal;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.InterfaceExplica;
import org.ceteca.explica.core.util.Converter;
import org.ceteca.explica.core.warehouse.ProductOT;

public class PriceListLineOT extends BaseVO implements Serializable{
	private long idPriceListLine;
	private PriceListOT priceList;
	private ProductOT product;
	private BigDecimal price;
	private double disccount;

	private Integer version=new Integer(0);
	
	

	private static final long serialVersionUID = 1L;

	
	
	
	
	
	
	
	public PriceListLineOT() {
		super();
		idPriceListLine=0;
		priceList=null;
		product=null;
		price=new BigDecimal(0);
		disccount=0.0;
	}

	
	
	
	
	
	
	public long getIdPriceListLine() {
		return idPriceListLine;
	}







	public void setIdPriceListLine(long idPriceListLine) {
		this.idPriceListLine = idPriceListLine;
	}







	public PriceListOT getPriceList() {
		return priceList;
	}







	public void setPriceList(PriceListOT priceList) {
		this.priceList = priceList;
	}







	public ProductOT getProduct() {
		return product;
	}







	public void setProduct(ProductOT product) {
		this.product = product;
	}







	public BigDecimal getPrice() {
		return price;
	}







	public void setPrice(BigDecimal price) {
		this.price = price;
	}







	public double getDisccount() {
		return disccount;
	}







	public void setDisccount(double disccount) {
		this.disccount = disccount;
	}









	public Integer getVersion() {
		return version;
	}







	public void setVersion(Integer version) {
		this.version = version;
	}







	@Override
	public boolean equals(Long id) {
		return id==getIdPriceListLine();
		
	}

	@Override
	public String getEntityId() {
		return InterfaceExplica.EXPLICA_ENTITY_PRICELISTLINE_ID;
	}

	@Override
	public long getInternalId() {
		return getIdPriceListLine();
	}

	@Override
	public String getInternalValue() {
		return Converter.getInstance().toString(getPrice());
	}

	public String getPriceListName(){
		if (getPriceList()!=null)
			return getPriceList().getDescription();
		else
			return null;
		
	}

	public String getProductName(){
		if (getProduct()!=null)
			return getProduct().getDescription();
		else
			return null;
		
	}



	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getPriceList());
	        hcb.append(getProduct());
	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final PriceListLineOT other = (PriceListLineOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getPriceList(), other.getPriceList());
	            eqb.append(getProduct(), other.getProduct());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }




	
	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%% PRICE LIST LINE %%%%%%%%%%%%%%%%%%");
			result.append("\nID PRICE LIST LINE: ");
			result.append(getIdPriceListLine());
			
			result.append("\nPRICE LIST: ");
			result.append(getPriceListName());
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");

		}
		catch (Exception ex) {
			System.out.println("Error formatting PriceListLineOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}



}
